﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using UFSoft.UBF.Util.Log;
using UFIDA.U9.BS.Job.RequestClient;
using UFSoft.UBF.UI.ControlModel;
using UFSoft.UBF.UI.Engine.Builder;
using UFSoft.UBF.UI.WebControlAdapter;
using UFSoft.UBF.UI.IView;
using System.Data;
using UFIDA.U9C.Cust.ZL.BP.SOMBP;
using static UFIDA.U9C.Cust.ZL.PlugUI.TemplateClass;

namespace UFIDA.U9C.Cust.ZL.PlugUI
{
    /// <summary>
    /// 销售订单变更单界面
    /// </summary>
    public class SOModifyMainUIFormWebPart : UFSoft.UBF.UI.Custom.ExtendedPartBase
    {
        private UFIDA.U9.SCM.SM.SOModifyUIModel.SOModifyMainUIFormWebPart _strongPart;
        private static ILogger logger = LoggerManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
        
        public override void BeforeEventProcess(IPart Part, string eventName, object sender, EventArgs args, out bool executeDefault)
        {
            _strongPart = Part as UFIDA.U9.SCM.SM.SOModifyUIModel.SOModifyMainUIFormWebPart;
            if (_strongPart == null)
            {
                executeDefault = false;
                return;
            }



            UFWebButton4ToolbarAdapter adapter = sender as UFWebButton4ToolbarAdapter;

            if ((adapter != null) && (adapter.Action.Equals("ApproveClick", StringComparison.InvariantCultureIgnoreCase)))
            {
                if (this._strongPart.Model.SOModify.FocusedRecord != null && this._strongPart.Model.SOModify.FocusedRecord.ID > 0)
                {
                    UFIDA.U9C.Cust.ZL.BP.SOMBP.Proxy.OperateProxy proxy = new BP.SOMBP.Proxy.OperateProxy();

                    proxy.EntityID = this._strongPart.Model.SOModify.FocusedRecord.ID;
                    ReturnDTOData result = proxy.Do();
                    if (result.Code == 2)
                    {
                        this._strongPart.Model.ClearErrorMessage();
                        this._strongPart.Model.ErrorMessage.Message = result.Message;
                        executeDefault = false;
                        return;

                    }
                    this._strongPart.DataCollect();
                }
            }
            else if ((adapter != null) && (adapter.Action.Equals("DisApprove", StringComparison.InvariantCultureIgnoreCase)))
            {
            }
            executeDefault = true;



            base.BeforeEventProcess(Part, eventName, sender, args, out executeDefault);
        }


    }
}

